﻿//-----------------------------------------------------------------------
// <copyright file="WebBrowserTask.cs" company="In The Hand Ltd">
//     Copyright © 2013-14 In The Hand Ltd. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System;

namespace InTheHand.Phone.Tasks
{
    /// <summary>
    /// Allows an application to launch the web browser application.
    /// </summary>
    public sealed class WebBrowserTask
    {
        /// <summary>
        /// Gets or sets the URI to which the web browser application will navigate when it is launched.
        /// </summary>
        public System.Uri Uri { set; get; }

        /// <summary>
        /// Gets or sets the URL to which the web browser application will navigate when it is launched.
        /// </summary>
        public string URL
        {
            get
            {
                if(this.Uri != null)
                {
                    return this.Uri.OriginalString;
                }

                return null;
            }
            
            set
            {
                if (string.IsNullOrEmpty(value))
                {
                    this.Uri = null;
                }
                else
                {
                    this.Uri = new Uri(value);
                }
            }      
        }

        /// <summary>
        /// Shows the web browser application.
        /// </summary>
        public void Show()
        {
            Windows.System.Launcher.LaunchUriAsync(this.Uri);
        }
    }
}
